/*
 *  @(#)GSExceptionHandler.java
 * 
 *  Project: BUS
 * 
 *  Modify Information:
 *  =========================================================================
 *  Change History:
 *  Author     Date       Description
 *  ========== ========== ===================================================
 *  Jenny Li   2006-02-07 新增
 *
 *  Copyright Notice:
 *   Copyright (c) 2001-2005 Beijing HiTRUST Technology Co., Ltd. 1808 Room,
 *   Science & Technology Building, No. 9 South Street, Zhong Guan Cun,
 *   Haidian District, Beijing ,100081, China All rights reserved.
 *
 *   This software is the confidential and proprietary information of
 *   HiTRUST.COM, Inc. ('Confidential Information').  You shall not
 *   disclose such Confidential Information and shall use it only in
 *   accordance with the terms of the license agreement you entered
 *   into with HiTRUST.
 *
 *  Warning:
 *  =========================================================================
 */
package com.hitrust.gs.util.exception;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;

import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;


public class GSExceptionHandler extends ExceptionHandler {
	public ActionForward execute(
			Exception ex,
			ExceptionConfig ae,
			ActionMapping mapping,
			ActionForm formInstance,
			HttpServletRequest request,
			HttpServletResponse response)
	throws ServletException {
		String tErrCode = "";
		String tErrMsg = "";
		if(ex instanceof GSException){
			GSLogWriter.error("Catch Exception INFO:"+ex, ex);
			tErrCode =((GSException)ex).getCode();
			tErrMsg = ((GSException)ex).getMessage();
			if(tErrCode == null || tErrCode.trim().equals("")){
				tErrCode = GSException.E00001;
			}
			if(tErrMsg == null){
				tErrMsg = GSException.E00001_MSG;
			}
			request.setAttribute("exception_code",tErrCode);
			request.setAttribute("exception_desc",tErrMsg);
		}else{
			GSLogWriter.error("Catch Exception INFO:"+ex, ex);
			tErrMsg = ex.getMessage();
			if(tErrMsg == null){
				tErrMsg = GSException.E00001_MSG;
			}
			request.setAttribute("exception_code",GSException.E00001);
			request.setAttribute("exception_desc",tErrMsg);
		}
		return mapping.findForward(GSBaseConstants.FORWARD_EXCEPTION);

	}
}
